from flask import Flask, request
import time
import os
from flask_cors import CORS

app = Flask(__name__)
CORS(app)  # 添加这一行以启用 CORS 支持

@app.route('/hello', methods=['POST'])
def hello():
    # 接收从前端发送的JSON数据
    data = request.json
    print(data)
    
    # # 检查是否收到了正确的数据
    # if data is None or 'image_name' not in data:
    #     return "No valid data received"
    
    # # 获取图片名称
    # image_name = data['image_name']
    
    # # 构建图片路径
    # image_path = os.path.join('', image_name)
    
    # 执行命令，使用新的图片路径
    command = "python3 onnx_inference.py -m yolox_s.onnx -i ./photo/"+ data +" -o outdir -s 0.3 --input_shape 640,640"   # 修正命令字符串
    print(command)
    a = os.system(command)
    print("dddddddddddddddddddddddd")
    #print(a)

    #return "Received image name: {}. Processed image using path: {}".format(image_name, image_path)
    return "Received data: " + str(data)

if __name__ == '__main__':
    app.run(debug=True)
